$(function() {
	var ary = new Array();
	var page = 1;
	$("#create_btn").click(function(){
		location.href = "http://yx.fxtourong.com/V1/Goods/create_query.html";
	});
	$("#foodimg3").click(function(){
		location.href = "mine3.html";
	});
	$("#foodimg2").click(function(){
		location.href = "queryfind.html";
	});
	$("#foodimg1").click(function(){
		location.href = "queryindex.html";
	});
	
	var $modal = $('#my-modal-loading');
	getData();
	
	function getData(){
		$modal.modal();
		console.log("page:" + page);
		$.ajax({
			type: "POST",
			url: "http://yx.fxtourong.com/V1/Circle/myCircleDynamic",
			data: {
				token : localStorage.getItem("token"),
				page: page
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				var code = data.code;
				console.log("code:" + data.code);
				if(code == "1") {
					isFirst = true;
					var jsonStr = data.data;
					for(var i = 0; i<jsonStr.length; i++){
						var industry = jsonStr[i];
						ary.push(industry);
						var typeStr = "语音";
						if(industry.g_type == "1"){
							typeStr = "语音";
						} else if(industry.g_type == "3") {
							typeStr = "文本";
						} else {
							typeStr = "图文";
						}
						var countimage = 0;
						if(typeStr == "图文"){
							countimage = industry.cover.length;
							for(var j = 0; j < countimage; j++){
								if(j == 0){
									image1 = industry.cover[j];
								} else if(j == 1){
									image2 = industry.cover[j];
								} else {
									image3 = industry.cover[j];
								}
							}
						} 
						console.log("image:" + countimage);
						if(typeStr == "语音"){
							$("#query_ul").append("<li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left detail_item' onclick=''>" + 
					        "<div class='am-u-sm-2 am-list-thumb'>" + 
					          "<img src='" + industry.avatar + "' class='am-circle' style='width: 40px;height: 40px;margin-left: 14px;display: inline;margin-top: 4px;'/>" + 
					        "</div>" + 
					        "<div class='am-u-sm-10 am-list-main'>" + 
					            "<div class='am-list-item-text'><span style='font-size: 15px;color: #5b6a92;'>" + industry.nickname + "</span>" +
					            "</div>" +
					            "<div class='am-list-item-text' style='margin-top: 8px;margin-right: 10px;'><span style='font-size: 14px;color: #333;'>" + industry.details + "</span></div>" + 
								"<div class='am-list-item-text' style='margin-top: 12px;'>" + 
					            	"<img src='" + "../../Public/yx/img/yuyin_tiao.svg" + "' style='width: 50%;display: inline;'/>" + 
					            "</div>" +
								"<div class='am-list-item-text' style='margin-top: 8px;'>" +
									"<span style='font-size: 14px;color: #BBBBBB;'>" + industry.created_time + "</span>" +
									"<span onclick='' class='circle_name' value='" + (((page-1) * 10) + i) + "' style='font-size: 14px;color: #5b6a92;float: right;margin-right: 10px;'>" + "#" + industry.circle_name + "#"  + "</span>" + 
								"</div>" + 
					        "</div>" + 
				      	"</li>");
						} else if(typeStr == "文本") {
							$("#query_ul").append("<li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left detail_item' onclick=''>" + 
					        "<div class='am-u-sm-2 am-list-thumb'>" + 
					          "<img src='" + industry.avatar + "' class='am-circle' style='width: 40px;height: 40px;margin-left: 14px;display: inline;margin-top: 4px;'/>" + 
					        "</div>" + 
					        "<div class='am-u-sm-10 am-list-main'>" + 
					            "<div class='am-list-item-hd'><span style='font-size: 15px;color: #5b6a92;'>" + industry.nickname + "</span>" +
					            "<span style='font-size: 16px;color: #0000FF;float: right;margin-right: 10px;display:none;'>" + "详情>>" + "</span>" +
					            "</div>" +
					            "<div class='am-list-item-text' style='margin-top: 8px;margin-right: 10px;'><span style='font-size: 14px;color: #333;'>" + industry.details + "</span></div>" + 
								"<div class='am-list-item-text' style='margin-top: 8px;'>" + 
									"<span style='font-size: 14px;color: #BBBBBB;'>" + industry.created_time + "</span>" +
									"<span onclick='' class='circle_name' value='" + (((page-1) * 10) + i) + "' style='font-size: 14px;color: #5b6a92;float: right;margin-right: 10px;'>" + "#" + industry.circle_name + "#"  + "</span>" + 
								"</div>" + 
					        "</div>" + 
				      	"</li>");
						} else {
							if(countimage == 1){
								$("#query_ul").append("<li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left detail_item' onclick=''>" + 
					        "<div class='am-u-sm-2 am-list-thumb'>" + 
					          "<img src='" + industry.avatar + "' class='am-circle' style='width: 40px;height: 40px;margin-left: 14px;display: inline;margin-top: 4px;'/>" + 
					        "</div>" + 
					        "<div class='am-u-sm-10 am-list-main'>" + 
					            "<div class='am-list-item-hd'><span style='font-size: 15px;color: #5b6a92;'>" + industry.nickname + "</span>" +
					            "<span style='font-size: 16px;color: #0000FF;float: right;margin-right: 10px;display:none;'>" + "详情>>" + "</span>" +
					            "</div>" +
					            "<div class='am-list-item-text' style='margin-top: 2px;margin-right: 10px;'><span style='font-size: 14px;color: #333;'>" + industry.details + "</span></div>" + 
								"<div style='margin-top: -6px;'>" + 
									"<img src='" + image1 + "' class='am-radius' style='width:108px;height: 148px;display: inline;margin-top: 14px;'/>" + 
								"</div>" + 
								"<div class='am-list-item-text' style='margin-top: 8px;'>" + 
									"<span style='font-size: 14px;color: #BBBBBB;'>" + industry.created_time + "</span>" +
									"<span onclick='' class='circle_name' value='" + (((page-1) * 10) + i) + "' style='font-size: 14px;color: #5b6a92;float: right;margin-right: 10px;'>" + "#" + industry.circle_name + "#"  + "</span>" + 
								"</div>" + 
					        "</div>" + 
				      	"</li>");
							} else if (countimage == 2){
								$("#query_ul").append("<li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left detail_item' onclick=''>" + 
					        "<div class='am-u-sm-2 am-list-thumb'>" + 
					          "<img src='" + industry.avatar + "' class='am-circle' style='width: 40px;height: 40px;margin-left: 14px;display: inline;margin-top: 4px;'/>" + 
					        "</div>" + 
					        "<div class='am-u-sm-10 am-list-main'>" + 
					            "<div class='am-list-item-hd'><span style='font-size: 15px;color: #5b6a92;'>" + industry.nickname + "</span>" +
					            "<span style='font-size: 16px;color: #0000FF;float: right;margin-right: 10px;display:none;'>" + "详情>>" + "</span>" +
					            "</div>" +
					            "<div class='am-list-item-text' style='margin-top: 8px;margin-right: 10px;'><span style='font-size: 14px;color: #333;'>" + industry.details + "</span></div>" + 
								"<div style='margin-top: -6px;'>" + 
									"<img src='" + image1 + "' class='am-radius' style='width:68px;height: 68px;display: inline;margin-top: 14px;'/>" + 
									"<img src='" + image2 + "' class='am-radius' style='width:68px;height: 68px;display: inline;margin-top: 14px;margin-left: 6px;'/>" + 
								"</div>" + 
								"<div class='am-list-item-text' style='margin-top: 8px;'>" + 
									"<span style='font-size: 14px;color: #BBBBBB;'>" + industry.created_time + "</span>" +
									"<span onclick='' class='circle_name' value='" + (((page-1) * 10) + i) + "' style='font-size: 14px;color: #5b6a92;float: right;margin-right: 10px;'>" + "#" + industry.circle_name + "#"  + "</span>" + 
								"</div>" + 
					        "</div>" + 
				      	"</li>");
							} else {
								$("#query_ul").append("<li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left detail_item' onclick=''>" + 
					        "<div class='am-u-sm-2 am-list-thumb'>" + 
					          "<img src='" + industry.avatar + "' class='am-circle' style='width: 40px;height: 40px;margin-left: 14px;display: inline;margin-top: 4px;'/>" + 
					        "</div>" + 
					        "<div class='am-u-sm-10 am-list-main'>" + 
					            "<div class='am-list-item-hd'><span style='font-size: 15px;color: #5b6a92;'>" + industry.nickname + "</span>" +
					            "<span style='font-size: 16px;color: #0000FF;float: right;margin-right: 10px;display:none;'>" + "详情>>" + "</span>" +
					            "</div>" +
					            "<div class='am-list-item-text' style='margin-top: 8px;margin-right: 10px;'><span style='font-size: 14px;color: #333;'>" + industry.details + "</span></div>" + 
								"<div style='margin-top: -6px;'>" + 
									"<img src='" + image1 + "' class='am-radius' style='width:68px;height: 68px;display: inline;margin-top: 14px;'/>" + 
									"<img src='" + image2 + "' class='am-radius' style='width:68px;height: 68px;display: inline;margin-top: 14px;margin-left: 6px;'/>" + 
									"<img src='" + image3 + "' class='am-radius' style='width:68px;height: 68px;display: inline;margin-top: 14px;margin-left: 6px;'/>" + 
								"</div>" + 
								"<div class='am-list-item-text' style='margin-top: 8px;'>" + 
									"<span style='font-size: 14px;color: #BBBBBB;'>" + industry.created_time + "</span>" +
									"<span onclick='' class='circle_name' value='" + (((page-1) * 10) + i) + "' style='font-size: 14px;color: #5b6a92;float: right;margin-right: 10px;'>" + "#" + industry.circle_name + "#"  + "</span>" + 
								"</div>" + 
					        "</div>" + 
				      	"</li>");
							}
						}
					}
				} else {
					$modal.modal('close');
				}
			},
			error: function(e){
				$modal.modal('close');
				alert("服务请求异常！");
			}
		});
	}
	
	$(document).on("click",".detail_item",function(){
			var m = $(this).val();
			localStorage.setItem("goods_id", ary[m].goods_id);
			localStorage.setItem("cid", ary[m].cid);
			var cid = ary[m].cid;
			var g_type = ary[m].g_type;
			console.log("cid:" + ary[m].cid);//1是话题3是动态
			if(cid == "1"){
				location.href = "voice_topic_details.html";
			} else {
				if(g_type == "1"){//语音
					location.href = "dongtai_detail_yuyin.html";
				} else if (g_type == "2"){//图文
					location.href = "dongtai_detail.html";
				} else if (g_type == "3"){//纯文本
					location.href = "dongtai_detail.html";
				}
			}
	});
	
	$(document).on("click",".circle_name",function(){
			var m = $(this).attr("value");
			console.log("ppppppppppppppp:" + m);
			localStorage.setItem("query_id", ary[m].circle_id);
//			localStorage.setItem("query_role", ary[m].type);
			location.href = "query_detail.html";
			return false;
	});
	
	var isFirst = true;
	
	$(window).scroll(function() {
	    if ($(document).scrollTop() >= ($(document).height() - $(window).height())) {
			if(isFirst){
				isFirst = false;
				page = page + 1;
				getData();
			}
			
	    }
  	});
	
});